package dao.Impl;

import dao.BaseDao;
import dao.Book_sortDao;
import entity.Book_sort;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wangying
 * @date 2025/2/21 16:26
 * title
 */
public class Book_sortDaoImpl extends BaseDao implements Book_sortDao {
    @Override
    public List<Book_sort> getAll() {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<Book_sort> list = new ArrayList<>();
        try {
            conn = getConnection();
            String sql = "SELECT * from book_sort";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                Book_sort book_sort = new Book_sort();
                book_sort.setId(rs.getInt("id"));
                book_sort.setName(rs.getString("name"));
                list.add(book_sort);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeAll(rs, ps, conn);
        }
        return list;
    }
}
